package com.wb.fengzhuang.lianxi;

import java.util.Random;

/**
 * @author 黄衡熙
 * @version 1.0
 * @date 2025年07月20日14:41
 */
public class Poker {
    private  Card[] cards;
    public Card[] getCards() {
        return cards;
    }

    public void setCards(Card[] cards) {
        this.cards = cards;
    }
    public Poker() {
        //此处填充五十四张牌
        cards=new Card[54];
        String[] colors={"黑桃","红心","梅花","方块"};
        String[] nums={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
        int count=0;
        for (int i=0;i<colors.length;i++) {
            for (int j=0;j<nums.length;j++) {
                Card card = new Card();
                card.setColor(colors[i]);
                card.setNum(nums[j]);
                cards[count++] = card;
            }
        }
        Card card1 = new Card();
        card1.setColor("红色");
        card1.setNum("大王");
        cards[count++]=card1;
        Card card2 = new Card();
        card2.setColor("黑色");
        card2.setNum("小王");
        cards[count]=card2;
    }
    public void shuffle() {
        // 需求二:创建一个洗牌方法shuffle,将牌的顺序打乱后展示
        // 备注:创建一个新的数组,向该数组中填充元素,元素的来源为未洗牌前的数组
        //将最终洗牌后的新数组赋值给全局属性

        Card[] cardsNew = new Card[cards.length];
        for (int i = 0; i <cards.length; i++) {
            cardsNew[i] =cards[i];
        }
        for (int i = cardsNew.length - 1; i > 0; i--) {
            int j=(int)(Math.random()*(i+1));
            Card temp = cardsNew[i];
            cardsNew[i] = cardsNew[j];
            cardsNew[j] = temp;
        }
        this.cards = cardsNew;
    }
}
